﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace i4pro_gruppe_d.Types
{
    public class User
    {
        private string userID;
        private string password;
        private int userType;

        public User()
        {
            userID = null;
            password = null;
            userType = -1;
        }
        
        public User(string _userID, string _password, int _userType)
        {
            UserID = _userID;
            Password = _password;
            UserType = _userType;
        }

        public string UserID 
        { 
            get { return userID; } 
            set
            {
                if (value.Length < 40)
                    userID = value;
            } 
        } 

        public string Password 
        { 
            get
            {
                return password;
            }
    
            set
            {
                if (value == "")
                    password = value;
                else
                {
                    value = Encrypt(value);
                    password = value;
                }
                
            } 
        }
        public int UserType
        {
            get
            {
                return userType;
            } 

            set
            {
                
                if (value >= -1)
                    userType = value;
            }
        }

        private SHA256Managed encrypt = new SHA256Managed();

        public string Encrypt(string pass)
        {
            byte[] passwordBytes = ASCIIEncoding.ASCII.GetBytes(pass);
            byte[] passwordHash = encrypt.ComputeHash(passwordBytes);
            return Convert.ToBase64String(passwordHash, 0, passwordHash.Length);
        }
    }
}
